package commRedisRpc

import (
	"encoding/json"
	commRedisRpc "gitee.com/fierce_wolf/go-fox-edge-common/commRedisList"
	"time"
)

type redisListChannelClientRespond struct {
	redisList commRedisRpc.RedisValueService
}

func (e *redisListChannelClientRespond) Pop(channelType string, hashKey string, timeout time.Duration) (*ChannelRespondVO, error) {
	jsn, err := e.redisList.PHGet("fox-edge:list:channel:"+channelType+":respond", hashKey, timeout)
	if err != nil {
		return nil, err
	}
	if jsn == "" {
		return nil, err
	}

	var vo ChannelRespondVO
	err = json.Unmarshal([]byte(jsn), &vo)
	if err != nil {
		return nil, err
	}

	return &vo, nil
}
